<?php
require "smarty/Smarty.class.php";
/**
 * 模板类,与smarty结合
 * @copyright   Copyright(c) 2012
 * @author      cnluckylee <cnluckylee@gmail.com>
 * @version     1.0
 */
final class Template extends Smarty{
        public $template_name = null;
		public $tpl=null;
		 function __construct()
		{
			$this->tpl = new Smarty;
		}
        public function init($template_name,$data = array()) {
        		foreach($data as $k=>$v)
        		{
        			$this->tpl->assign($k, $v);
        		}
                $view_file = VIEW_PATH . '/' . $template_name . '.tpl';
                $this->tpl->display($view_file);
        }

        /**
         * 写入静态化文件
         * @access      public
         */
//        public function toHtml() {
//                if (!is_dir(ROOT_PATH . '/cache/template/')) {
//                        mkdir(ROOT_PATH . '/cache/template/', 0777);
//                }
//                if (!$fp = @fopen(ROOT_PATH . '/cache/template/' . $filename . '.html', 'w')) {
//                        trigger_error('文件 ' . ROOT_PATH . '/cache/template/' . $filename . '.html' . ' 不能打开');
//                }
//                if (fwrite($fp, $content) == FALSE) {
//                        trigger_error('文件 ' . ROOT_PATH . '/cache/template/' . $filename . '.html' . ' 写入失败');
//                }
//                fclose($fp);
//        }

}

